package cn.t.web.user;

import cn.t.core.controller.BaseController;
import cn.t.core.mode.YesNoEnum;
import cn.t.dto.user.CustomerFirmDTO;
import cn.t.core.enums.base.BaseStatusEnum;
import cn.t.facade.user.CustomerFirmFacade;
import cn.t.facade.user.CustomerInfoFacade;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 单位信息表服务入口
 *
 * @author l
 */
@Slf4j
@RestController
@RequestMapping("customerFirm")

@AllArgsConstructor
public class CustomerFirmController extends BaseController<CustomerFirmDTO, CustomerFirmFacade> {



    @PostMapping("/create")
    public Long create(@Valid @RequestBody CustomerFirmDTO customerFirmDTO) {
        return customerInfoFacade.createFirm(customerFirmDTO);
    }


    @PostMapping("/find")
    public List<CustomerFirmDTO> find(@RequestBody CustomerFirmDTO customerFirmDTO) {

        customerFirmDTO.setStatus(String.valueOf(BaseStatusEnum.AVAILABLE.getCode()));
        customerFirmDTO.setIsDeleted(YesNoEnum.FALSE);


        return facade.queryList(customerFirmDTO, 0, 10000, "firm_code", "asc");
    }


    @Autowired
    private CustomerInfoFacade customerInfoFacade;

}

